package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.privilege.model.User;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

@Entity
@Indexed
@Table(name = "fp_approvaldefine")
@CriteriaEnhancers(criteriaEnhancers = { @CriteriaEnhancer(impl = OrderCriteriaEnhancer.class,parameter="setupTime:desc") })
public class ApprovalDefine extends BaseModel {

	private static final long serialVersionUID = 7765168222446256894L;

	@Id
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkApprovalDefine;

	/** 审批明细 */
	@OneToMany(mappedBy = "approvalDefine", cascade = CascadeType.ALL, orphanRemoval = true)
	@IndexedEmbedded(depth = 1)
	@OrderBy("sequenceNumber")
	private Set<ApprovalDefineItem> approvalDefineItems;

	/** 描述 */
	@Column
	@Field
	private String description;

	/** 业务类型 */
	@Column
	@Field
	@In
	private String serviceType;

	/** 对应模型完整路径 */
	@Column
	@Field
	private String modelClass;

	/** 设置时间 */
	@Column
	@Field
	@Between
	private Date setupTime;

	/** 业务实现接口 */
	@Column
	@Field
	private String serviceImpl;

	/** 业务也对应链接 */
	@Column
	@Field
	private String pageLink;

	/** 设置人 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkUser")
	@IndexedEmbedded(depth = 1)
	private User user;

	/** 状态 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private Status status;

	/** 状态 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Status {
		Setting("已启用"), BlockUp("停用");

		private String display;

		Status(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	/** 审批类型 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private ApporvalType apporvaltype;

	/** 审批类型 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum ApporvalType {
		Serialization("顺序"), Concurrence("并行");

		private String display;

		ApporvalType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	@Version
	private Integer version;

	public Long getPkApprovalDefine() {
		return pkApprovalDefine;
	}

	public void setPkApprovalDefine(Long pkApprovalDefine) {
		this.pkApprovalDefine = pkApprovalDefine;
	}

	public Set<ApprovalDefineItem> getApprovalDefineItems() {
		return approvalDefineItems;
	}

	public void setApprovalDefineItems(
			Set<ApprovalDefineItem> approvalDefineItems) {
		this.approvalDefineItems = approvalDefineItems;
	}

	public String getServiceType() {
		return serviceType;
	}

	public void setServiceType(String serviceType) {
		this.serviceType = serviceType;
	}

	public Date getSetupTime() {
		return setupTime;
	}

	public void setSetupTime(Date setupTime) {
		this.setupTime = setupTime;
	}

	public String getServiceImpl() {
		return serviceImpl;
	}

	public void setServiceImpl(String serviceImpl) {
		this.serviceImpl = serviceImpl;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public ApporvalType getApporvaltype() {
		return apporvaltype;
	}

	public void setApporvaltype(ApporvalType apporvaltype) {
		this.apporvaltype = apporvaltype;
	}

	public String getModelClass() {
		return modelClass;
	}

	public void setModelClass(String modelClass) {
		this.modelClass = modelClass;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getPageLink() {
		return pageLink;
	}

	public void setPageLink(String pageLink) {
		this.pageLink = pageLink;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

}
